package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.limao.DBDataClass.CrowdUserParentClass;
import com.limao.DbConnection.DbConnectionManager;



public class CrowdUserParentProvider {

	private static class UserParentProviderContainer {
		private static CrowdUserParentProvider instance = new CrowdUserParentProvider();
	}

	public static CrowdUserParentProvider getInstance() {
		return UserParentProviderContainer.instance;
	}

	private static final String T_User_Parent = "cd_user_parent";
	private static final String cd_user_parent_LOAD="select * from "+T_User_Parent+" where userid=?";
	
	
	
	// 查询 by id
	public CrowdUserParentClass loadUserParent(int id) {
		
		CrowdUserParentClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement(cd_user_parent_LOAD);
			pstmt.setInt(1, id);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				tmp = new CrowdUserParentClass();
				tmp.userid = rs.getString("userid") ;
				tmp.pid0 = rs.getString("pid0");
				tmp.pid1 = rs.getString("pid1");
				tmp.pid2 = rs.getString("pid2");
				tmp.time = rs.getString("time");
				tmp.pid3 = rs.getString("pid3");
				tmp.pid4 = rs.getString("pid4");

			}


			
		} catch (Exception e) {
			tmp = null;
			e.printStackTrace();
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return tmp;
	}
	
	
}
